setInterval(() => {
    ShowLeftTime(2018, 6, 10, 10)
}, 500);

function ShowLeftTime(year, month, date, h) {
    //得出剩余时间
    var now = new Date();
    var endDate = new Date(year, month - 1, date, h);
    var leftTime = endDate.getTime() - now.getTime();
    var leftsecond = parseInt(leftTime / 1000);
    var day = Math.floor(leftsecond / (60 * 60 * 24));
    var hour = Math.floor((leftsecond - day * 24 * 60 * 60) / 3600).toString().padStart(2, 0);
    var minute = Math.floor((leftsecond - day * 24 * 60 * 60 - hour * 3600) / 60).toString().padStart(2, 0);
    var second = Math.floor(leftsecond - day * 60 * 60 * 24 - hour * 60 * 60 - minute * 60).toString().padStart(2, 0);
    //显示剩余时间
    console.log("距离" + year + "年" + month + "月" + date + "日" +
        "还有" + day + "天" + hour + "小时" + minute + "分" + second + "秒");
}